<?php
namespace app\lib;


class DingtalkCryptPlus
{
    protected $token;
    protected $encoding_ase_key;
    protected $key;
    protected $crypt;

    public function __construct()
    {
        $token = CALL_BACK_TOKEN;
        $encoding_ase_key = CALL_BACK_AES_KEY;
        $key = DINGTALK_CORP_ID;

        require_once("../extend/taobao/crypto/DingtalkCrypt.php");
        $this->crypt = new \DingtalkCrypt($token, $encoding_ase_key, $key);

    }

    public function doDecryptAudit($signature, $timeStamp, $nonce, $encrypt)
    {
        $msg = '';
        $errCode = $this->crypt->DecryptMsg($signature, $timeStamp, $nonce, $encrypt, $msg);
        return ['code' => $errCode, 'msg' => $msg];
    }

    public function doEncryptAudit($plain, $timeStamp, $nonce)
    {
        $errCode = $this->crypt->EncryptMsg($plain, $timeStamp, $nonce, $msg);

        return ['code' => $errCode, 'msg' => $msg];
    }

}